package cn.virens.util;

/**
 * <br>
 * (c) Copyright 2016 by <br>
 * 
 * @description :数字转换类 <br>
 * @file_name :NumberUitl.java <br>
 * @system_name :car-util <br>
 * @author :yyzh <br>
 * @创建时间 :2016年4月12日 下午3:10:35
 */
public class NumberUitl extends TextUtils {

	public static Integer parseInt(String str) {
		return parseInt(str, null);
	}

	public static Integer parseInt(Object obj, Integer defaultValue) {
		if (obj instanceof Number) { return ((Number) obj).intValue(); }
		if (!(obj instanceof String)) { return defaultValue; }
		try {
			return Integer.parseInt(obj.toString());
		} catch (Exception e) {
			return defaultValue;
		}
	}

	public static Long parseLong(String str) {
		return parseLong(str, null);
	}

	public static Long parseLong(Object obj, Long defaultValue) {
		if (obj instanceof Number) { return ((Number) obj).longValue(); }
		if (!(obj instanceof String)) { return defaultValue; }
		try {
			return Long.parseLong(obj.toString());
		} catch (Exception e) {
			return defaultValue;
		}
	}

	public static Double parseDouble(String str) {
		return parseDouble(str, null);
	}

	public static Double parseDouble(Object obj, Double defaultValue) {
		if (obj instanceof Number) { return ((Number) obj).doubleValue(); }
		if (!(obj instanceof String)) { return defaultValue; }
		try {
			return Double.parseDouble(obj.toString());
		} catch (Exception e) {
			return defaultValue;
		}
	}

	public static Float parseFloat(String str) {
		return parseFloat(str, null);
	}

	public static Float parseFloat(Object obj, Float defaultValue) {
		if (obj instanceof Number) { return ((Number) obj).floatValue(); }
		if (!(obj instanceof String)) { return defaultValue; }
		try {
			return Float.parseFloat(obj.toString());
		} catch (Exception e) {
			return defaultValue;
		}
	}

}
